package com.controller;


import com.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@Slf4j
public class UploadController {

    @PostMapping("/upload")
    public Result upload(String username , Integer age, MultipartFile image) throws IOException {
        log.info("文件上传:{}{}{}", username, age, image);


        int index = image.getOriginalFilename().lastIndexOf(".");
        String extname = image.getOriginalFilename().substring(index);
        String newFileName = System.currentTimeMillis() + extname;

        log.info("新文件名：{}", newFileName);
        image.transferTo(new File("D:\\images\\"  + newFileName));
        return Result.success();
    }
}
